package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrdersMapper {

    /**
     * 得到当天的总销售额
     * @param map 存有查询条件的集合
     * @return
     */
    Double getOrderAmout(Map map);

    /**
     * 创建订单
     * @param orders
     */
    void insertNew(Orders orders);
    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
//    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    List<Orders> getByNumberAndUserId(String orderNumber, Long userId, Integer status);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    @Select("select * from orders where id = #{id} ;")
    Orders selectById(Long id);

    /**
     * 取消订单
     * @param id
     * @param userCancel
     * @param cancelTime
     */
    void cancelOrder(Long id, String userCancel, LocalDateTime cancelTime);

    /**
     * 查询订单
     * @param ordersPageQueryDTO
     * @return
     */
    Page<OrderVO> selectUserOrder(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 待派送计数
     * @return
     */
    @Select("select count(*) from orders where status = 3 ;")
    Integer countConfirmed();

    /**
     * 派送中计数
     * @return
     */
    @Select("select count(*) from orders where status = 4 ;")
    Integer countdeliveryInProgress();

    /**
     * 待接单数量
     * @return
     */
    @Select("select count(*) from orders where status = 2 ;")
    Integer counttoBeConfirmed();

    /**
     * 根据状态和下单时间查询订单
     * @param status
     * @param orderTime
     */
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> getByStatusAndOrdertimeLT(Integer status, LocalDateTime orderTime);

    @Select("select * from orders where id = #{id} ;")
    Orders getById(Long id);

    /**
     * 查询每天订单
     * @param beginTime
     * @param endTime
     * @param status
     * @return
     */
    Long getOrderCount(LocalDateTime beginTime, LocalDateTime endTime, Integer status);

    List<GoodsSalesDTO> SalesTop10(LocalDateTime beginTime, LocalDateTime endTime);
}
